<template>
  <span>{{ label }}</span>
</template>
<script>
import dictionary from '@/config/dictionary'

export default {
  name: 'DictionaryLabel',
  props: {
    value: {
      type: [String, Number, Boolean, Object],
    },
    valueKey: {
      type: String,
      default: () => {
        return 'value'
      },
    },
    labelKey: {
      type: String,
      default: () => {
        return 'label'
      },
    },
    dicKey: {
      type: String,
    },
    dics: {
      type: Array,
    },
  },
  computed: {
    label() {
      let dics
      if (this.dics) {
        dics = this.dics
      } else {
        dics = dictionary[this.dicKey]
      }

      for (let i in dics) {
        if (dics[i][this.valueKey] == this.value) {
          return dics[i][this.labelKey]
        }
      }
      return ''
    },
  },
}
</script>
